package BookManagement.operation;

import BookManagement.book.Bookshelf;

import java.util.Scanner;

public class DelBook implements IBusinessOperation{
    @Override
    public void work(Bookshelf bookshelf) {
        System.out.println("删除图书……");
        System.out.println("请输入要删除的书籍名称：");
        String name = "";
        Scanner scan = new Scanner(System.in);
        name = scan.nextLine();

        //先计算当前书籍的数量
        int number = bookshelf.book_umber;
        //记录要删除书籍的下标
        int i = 0;
        int pos = 0;
        for(; i<number; i++){
            if(name.equals(bookshelf.books[i].getName())) {
                pos = i;
                break;
            }
        }
        if(i >= number){
            System.out.println("要删除的书籍不存在！");
        }
        for(i=pos; i<number-1; i++){
            bookshelf.books[i] = bookshelf.books[i+1];
        }
        bookshelf.book_umber-=1;
        System.out.println("删除成功！");
    }
}
